package org.come.Jpanel;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;

import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;

import org.come.Frame.FactionAngelJframe;
import org.come.until.CutButtonImage;

import com.tool.btn.FactionBtn;
import com.tool.tcpimg.UIUtils;

public class FactionAngelModelJpanel extends JPanel {

    private JLabel labImg, labName, labDegree, labLvl;
    private FactionBtn btnLeft, btnRight;

    /**
     * 字段名:lvlNow 已添加的点数<br>
     */
    private int lvlNow = 0, lvlChange = 0;

    public FactionAngelModelJpanel() {
        this.setPreferredSize(new Dimension(324, 34));
        this.setOpaque(false);
        this.setLayout(null);

        getLabDegree();
        getLabImg();
        getLabLvl();
        getLabName();
        getBtnLeft();
        getBtnRight();
    }

    // 小成修炼：（每项抗性选择最多选择20点）
    // 1点修炼增加1.5的抗性：人法，仙法 ，鬼火，遗忘，物理
    // 1点修炼增加增加三尸虫抗性100点
    // 大成修炼抗性（没项抗性选择最多选择20点）
    // 1点修炼增加法术躲闪0.5
    // 1点修炼增加伤害减免0.5点
    public void showModel(int num, String[] values, FactionAngelJpanel factionAngelJpanel) {
        // 20001
        int skillNum = 0;
        if (num == 0) {
            labName.setText("抗鬼火");
            labLvl.setText("0/20");
            labDegree.setText("0.0%");
            skillNum = 1065;
        } else if (num == 1) {
            labName.setText("抗三尸虫");
            labLvl.setText("0/20");
            labDegree.setText("0.0%");
            skillNum = 1070;
        } else if (num == 2) {
            labName.setText("抗遗忘");
            labLvl.setText("0/20");
            labDegree.setText("0.0%");
            skillNum = 1075;
        } else if (num == 3) {
            labName.setText("抗物理");
            labLvl.setText("0/20");
            labDegree.setText("0.0%");
            skillNum = 1030;
        } else if (num == 4) {
            labName.setText("抗火");
            labLvl.setText("0/20");
            labDegree.setText("0.0%");
            skillNum = 1060;
        } else if (num == 5) {
            labName.setText("抗雷");
            labLvl.setText("0/20");
            labDegree.setText("0.0%");
            skillNum = 1050;
        } else if (num == 6) {
            labName.setText("抗水");
            labLvl.setText("0/20");
            labDegree.setText("0.0%");
            skillNum = 1055;
        } else if (num == 7) {
            labName.setText("抗风");
            labLvl.setText("0/20");
            labDegree.setText("0.0%");
            skillNum = 1045;
        } else if (num == 8) {
            labName.setText("抗中毒");
            labLvl.setText("0/20");
            labDegree.setText("0.0%");
            skillNum = 1020;
        } else if (num == 9) {
            labName.setText("抗封印");
            labLvl.setText("0/20");
            labDegree.setText("0.0%");
            skillNum = 1010;
        } else if (num == 10) {
            labName.setText("抗昏睡");
            labLvl.setText("0/20");
            labDegree.setText("0.0%");
            skillNum = 1015;
        } else if (num == 11) {
            labName.setText("抗混乱");
            labLvl.setText("0/20");
            labDegree.setText("0.0%");
            skillNum = 1005;
        } else if (num == 12) {
            labName.setText("抗震慑");
            labLvl.setText("0/20");
            labDegree.setText("0.0%");
            skillNum = 1025;
        } else if (num == 13) {
            labName.setText("物理躲闪");
            labLvl.setText("0/30");
            labDegree.setText("0.0%");
            skillNum = 1030;
        } else if (num == 14) {
            labName.setText("震慑躲闪");
            labLvl.setText("0/30");
            labDegree.setText("0.0%");
            skillNum = 1025;
        } else if (num == 15) {
            labName.setText("火法躲闪");
            labLvl.setText("0/30");
            labDegree.setText("0.0%");
            skillNum = 1060;
        } else if (num == 16) {
            labName.setText("雷法躲闪");
            labLvl.setText("0/30");
            labDegree.setText("0.0%");
            skillNum = 1050;
        } else if (num == 17) {
            labName.setText("水法躲闪");
            labLvl.setText("0/30");
            labDegree.setText("0.0%");
            skillNum = 1055;
        } else if (num == 18) {
            labName.setText("风法躲闪");
            labLvl.setText("0/30");
            labDegree.setText("0.0%");
            skillNum = 1045;
        } else if (num == 19) {
            labName.setText("毒法躲闪");
            labLvl.setText("0/30");
            labDegree.setText("0.0%");
            skillNum = 1020;
        } else if (num == 20) {
            labName.setText("封印躲闪");
            labLvl.setText("0/30");
            labDegree.setText("0.0%");
            skillNum = 1010;
        } else if (num == 21) {
            labName.setText("昏睡躲闪");
            labLvl.setText("0/30");
            labDegree.setText("0.0%");
            skillNum = 1015;
        } else if (num == 22) {
            labName.setText("混乱躲闪");
            labLvl.setText("0/30");
            labDegree.setText("0.0%");
            skillNum = 1005;
        } else if (num == 23) {
            labName.setText("遗忘躲闪");
            labLvl.setText("0/30");
            labDegree.setText("0.0%");
            skillNum = 1075;
        } else if (num == 24) {
            labName.setText("鬼火躲闪");
            labLvl.setText("0/30");
            labDegree.setText("0.0%");
            skillNum = 1065;
        } else if (num == 25) {
            labName.setText("三尸虫躲闪");
            labLvl.setText("0/30");
            labDegree.setText("0.0%");
            skillNum = 1070;
        } else if (num == 26) {
            labName.setText("水法伤害减免");
            labLvl.setText("0/30");
            labDegree.setText("0.0%");
            skillNum = 1055;
        } else if (num == 27) {
            labName.setText("火法伤害减免");
            labLvl.setText("0/30");
            labDegree.setText("0.0%");
            skillNum = 1060;
        } else if (num == 28) {
            labName.setText("鬼火伤害减免");
            labLvl.setText("0/30");
            labDegree.setText("0.0%");
            skillNum = 1065;
        } else if (num == 29) {
            labName.setText("风法伤害减免");
            labLvl.setText("0/30");
            labDegree.setText("0.0%");
            skillNum = 1045;
        } else if (num == 30) {
            labName.setText("雷法伤害减免");
            labLvl.setText("0/30");
            labDegree.setText("0.0%");
            skillNum = 1050;
        }
        labImg.setIcon(CutButtonImage.getImage("inkImg/old/skill/masterDoor/" + skillNum + ".png", 30, 30));
        labDegree.setForeground(Color.white);
        labLvl.setForeground(Color.WHITE);
        judgeName(values, labName.getText(), factionAngelJpanel);
    }

    /** 初始化数据 */
    public void judgeName(String[] values, String prefix, FactionAngelJpanel factionAngelJpanel) {
        double value = 0;
        lvlNow = 0;
        lvlChange = lvlNow;
        if(values != null&&!"".equals(values)){
            for (int i = 0; i < values.length; i++) {
                if (values[i].startsWith(prefix)) {
                    String[] vs = values[i].split("=");
                    if ("抗三尸虫".equals(vs[0])) {
                        lvlNow = (int) (Double.parseDouble(vs[1]) / 100);
                        value = lvlNow * 100D;
                    } else if (vs[0].endsWith("躲闪")) {
                        lvlNow = (int) (Double.parseDouble(vs[1]) / 0.5);
                        value = lvlNow * 0.5D;
                    } else if (vs[0].endsWith("减免")) {
                        lvlNow = (int) (Double.parseDouble(vs[1]) / 0.5);
                        value = lvlNow * 0.5D;
                    } else {
                        lvlNow = (int) (Double.parseDouble(vs[1]) / 1.5);
                        value = lvlNow * 1.5D;
                    }
                    lvlChange = lvlNow;
                    labDegree.setText(value + percentageIsTrue(vs[0]));
                    labLvl.setText(lvlNow + "/" + (factionAngelJpanel.getMenuType() == 1 ? 20 : 30));
                    factionAngelJpanel.setTypeLvlResidue(factionAngelJpanel.getTypeLvlResidue() + lvlNow);
                    break;
                }
            }
        }
    }

    /** 刷新数据 */
    public void refreshLvlChange() {
        int menuType = FactionAngelJframe.getFactionAngelJframe().getFactionAngelJpanel().getMenuType();
        double value = 0;
        String text = labName.getText();
        if ("抗三尸虫".equals(text)) {
            value = lvlChange * 100D;
        } else if (text.endsWith("躲闪")) {
            value = lvlChange * 0.5D;
        } else if (text.endsWith("减免")) {
            value = lvlChange * 0.5D;
        } else {
            value = lvlChange * 1.5D;
        }
        labDegree.setText(value + percentageIsTrue(text));
        labLvl.setText(lvlChange + "/" + (menuType == 1 ? 20 : 30));
    }
    /**获取数值*/
    public String getLvlValue() {
        double value = 0;
        String text = labName.getText();
        if ("抗三尸虫".equals(text)) {
            value = lvlChange * 100D;
        } else if (text.endsWith("躲闪")) {
            value = lvlChange * 0.5D;
        } else if (text.endsWith("减免")) {
            value = lvlChange * 0.5D;
        } else {
            value = lvlChange * 1.5D;
        }
        if (value==(int)value) {
            return (int)value+"";
        }
        return value+"";
    }
    public String percentageIsTrue(String text) {
        if ("抗三尸虫".equals(text)) {
            return "";
        } else {
            return "%";
        }
    }

    private ImageIcon icon;

    @Override
    protected void paintComponent(Graphics g) {
        // TODO Auto-generated method stub
        super.paintComponent(g);
        if (icon == null) {
            icon = CutButtonImage.getImage("inkImg/old/background/S173.png", -1, -1);
        }
        g.drawImage(icon.getImage(), 200, 6, 87, 22, null);
    }

    public JLabel getLabImg() {
        if (labImg == null) {
            labImg = new JLabel();
            labImg.setBounds(5, 2, 30, 30);
            this.add(labImg);
        }
        return labImg;
    }

    public void setLabImg(JLabel labImg) {
        this.labImg = labImg;
    }

    public JLabel getLabName() {
        if (labName == null) {
            labName = new JLabel("无敌闪躲");
            labName.setForeground(Color.white);
            labName.setFont(UIUtils.TEXT_FONT1);
            labName.setBounds(37, 7, 90, 20);
            this.add(labName);
        }
        return labName;
    }

    public void setLabName(JLabel labName) {
        this.labName = labName;
    }

    public JLabel getLabDegree() {
        if (labDegree == null) {
            labDegree = new JLabel("0.0%");
            labDegree.setForeground(Color.white);
            labDegree.setFont(UIUtils.TEXT_FONT1);
            labDegree.setBounds(140, 7, 50, 20);
            this.add(labDegree);
        }
        return labDegree;
    }

    public void setLabDegree(JLabel labDegree) {
        this.labDegree = labDegree;
    }

    public JLabel getLabLvl() {
        if (labLvl == null) {
            labLvl = new JLabel("0/20");
            labLvl.setForeground(Color.white);
            labLvl.setFont(UIUtils.TEXT_FONT1);
            labLvl.setBounds(202, 6, 60, 22);
            this.add(labLvl);
        }
        return labLvl;
    }

    public void setLabLvl(JLabel labLvl) {
        this.labLvl = labLvl;
    }

    public FactionBtn getBtnLeft() {
        if (btnLeft == null) {
            btnLeft = new FactionBtn("skin/8100226/button/12.png", 1, 18, this);
            btnLeft.setBounds(255, 9, 12, 16);
            this.add(btnLeft);
        }
        return btnLeft;
    }

    public void setBtnLeft(FactionBtn btnLeft) {
        this.btnLeft = btnLeft;
    }

    public FactionBtn getBtnRight() {
        if (btnRight == null) {
            btnRight = new FactionBtn("skin/8100226/button/11.png", 1, 19, this);
            btnRight.setBounds(270, 9, 12, 16);
            this.add(btnRight);
        }
        return btnRight;
    }

    public void setBtnRight(FactionBtn btnRight) {
        this.btnRight = btnRight;
    }

    public int getLvlNow() {
        return lvlNow;
    }

    public void setLvlNow(int lvlNow) {
        this.lvlNow = lvlNow;
    }

    public ImageIcon getIcon() {
        return icon;
    }

    public void setIcon(ImageIcon icon) {
        this.icon = icon;
    }

    public int getLvlChange() {
        return lvlChange;
    }

    public void setLvlChange(int lvlChange) {
        this.lvlChange = lvlChange;
    }

}